package test2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        List<int[]> list1 = new ArrayList<>();
        List<int[]> list2 = new ArrayList<>();

        for (int i = 0; i < a; i++) {
            int[] ints = new int[2];
            ints[0] = input.nextInt();
            ints[1] = input.nextInt();
            list1.add(ints);
        }

        for (int i = 0; i < b; i++) {
            int[] ints = new int[2];
            ints[0] = input.nextInt();
            ints[1] = input.nextInt();
            list2.add(ints);
        }

        int res = 0;
        int i1 = 0, i2 = 0;
        while (i1 < a && i2 < b) {
            int x = list1.get(i1)[0];
            int y = list2.get(i2)[0];
            if (x == y) {
                res += list1.get(i1)[1] * list2.get(i2)[1];
                i1 ++;
                i2 ++;
            } else if (x > y) {
                i2 ++;
            } else {
                i1 ++;
            }
        }
        System.out.println(res);
    }
}
